package com.sdl.timesblogmp.controller;


import com.sdl.timesblogmp.model.entity.Tag;
import com.sdl.timesblogmp.model.vo.ApiResult;
import com.sdl.timesblogmp.model.vo.PageParam;
import com.sdl.timesblogmp.service.TagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sdl
 * @since 2020-05-11
 */
@Api(value = "标签接口", tags = "标签接口")
@RestController
@RequestMapping("/tag")
public class TagController {
    @Resource
    private TagService tagService;
    @ApiOperation(value = "获取所有标签")
    @GetMapping("/list")
    public ApiResult getallTag(PageParam pageParam){
        return ApiResult.success( tagService.findTagInfo(pageParam)) ;
    }
    @ApiOperation(value = "新增一个标签")
    @PostMapping("/add")
    public ApiResult addtag(@RequestBody Tag tag){
        return ApiResult.success(tagService.addTag(tag));
    }
    @ApiOperation(value = "删除一个标签")
    @DeleteMapping("/del/{id}")
    public ApiResult deletetag(@PathVariable Integer id){
        tagService.delTag(id);
        return ApiResult.success();
    }
    @ApiOperation(value = "更新标签信息")
    @PutMapping("/update")
    public ApiResult updatetag(@RequestBody Tag tag){
        tagService.updateById(tag);
        return ApiResult.success();
    }
}

